package com.baili.controller.productionorder;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baili.dto.BaseTransferEntity;
import com.baili.dto.ProductOrder;
import com.baili.service.planner.PlannerService;
import com.baili.service.productionorder.ProductionOrderService;
import com.baili.service.user.UserService;
import com.baili.util.MobileConfig;
import com.baili.util.StringUtil;

/** 
 * @author iceX
 * @version 创建时间：2016年3月25日 上午11:29:12 
 * @Name: ProductionOrderController.java生产通知单
 */
@Controller
@RequestMapping(value = "")
public class ProductionOrderController {
	private static Logger log = Logger
			.getLogger(ProductionOrderController.class);

	@Autowired
	private ProductionOrderService productionOrderService;
	@Autowired
	private PlannerService plannerService;
	@Autowired
	private UserService userService;

	
	
	
	
	/**
	 * 公司领导-生产通知单表查询-计划进度统计
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/selectProductTeamList")
	@ResponseBody
	public BaseTransferEntity selectProductTeamList(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();

		
		List list = productionOrderService.selectProductTeamList();
		
		
		baseTransferEntity.setData(list);
		

		baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
		return baseTransferEntity;
	}
	/**
	 * 公司领导-生产通知单表查询-拖动轮次
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/dragRound")
	@ResponseBody
	public BaseTransferEntity dragRound(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();

		String productCode = request.getParameter("productCode"); // 产品代码
		String scheduleNo = request.getParameter("scheduleNo"); // 产品代码
		// 获取页面要移动的两个轮次
		int tmove = Integer.parseInt(request.getParameter("tmove")); // 拖动的轮次
		int bmove = Integer.parseInt(request.getParameter("bmove")); // 位置被占的轮次
		// 先判断是向上移动 还是向下移动
		ProductOrder tpo = new ProductOrder();
		ProductOrder bpo = new ProductOrder();
		bpo.setRound(bmove);
		bpo.setProductCode(productCode);
		bpo.setScheduleNo(scheduleNo);
		tpo.setRound(tmove);
		tpo.setProductCode(productCode);
		tpo.setScheduleNo(scheduleNo);
		if (tmove > bmove) {// 向上移动
			
			// 然后将最下面的那个round属性赋值为bmove
			ProductOrder p = productionOrderService
					.getProductionOrderByRound(tpo);
			p.setRound(bmove);
			
			
			// 然后将bmove至tmove之间的向下移动即为 round 属性+1
			for (int i = tmove - 1; i >= bmove; i--) {
				tpo.setRound(i);
				ProductOrder pb = productionOrderService
						.getProductionOrderByRound(tpo);
				if(pb.getId() != 0){
					
					pb.setRound(i + 1);
					// 将其保存到数据库返回成功信号
					productionOrderService.updateProductionOrder(pb);
				}
			}
			
			productionOrderService.updateProductionOrder(p);
		} else if (tmove < bmove) {// 向下移动

			// 然后将最上面的那个round属性赋值为bmove
			ProductOrder p = productionOrderService
					.getProductionOrderByRound(tpo);
			p.setRound(bmove);
			// 先将tmove至bmove之间的向上移动一位即为round属性—1
			for (int i = tmove + 1; i <= bmove; i++) {
				tpo.setRound(i);
				ProductOrder pb = productionOrderService
						.getProductionOrderByRound(tpo);
				if(pb.getId() != 0){
					
					pb.setRound(i - 1);
					// 将其保存到数据库返回成功信号
					productionOrderService.updateProductionOrder(pb);
				}
			}
			productionOrderService.updateProductionOrder(p);

		}

		baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
		baseTransferEntity.setData("");
		baseTransferEntity.setDesc(MobileConfig.getString("msg.global.success"));
		return baseTransferEntity;
	}

	/**
	 * 公司领导-生产通知单表查询-计划进度统计
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getProductionOrderList")
	@ResponseBody
	public BaseTransferEntity getProductionOrderList(
			HttpServletRequest request, HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			String startTime = request.getParameter("startTime");
			String overTime = request.getParameter("overTime");
			ProductOrder productOrder = new ProductOrder();
			
//			if(StringUtil.isEmpty(startTime) && StringUtil.isEmpty(overTime)){
//				
//				startTime = sdf.format(StringUtil.MinusDay(new Date(), 7));
//				
//				overTime = sdf.format(new Date());
//			}
			
			productOrder.setStartTime(startTime);
			
			if(!StringUtil.isEmpty(overTime)){
				
				Date overTimeDate = StringUtil.parseDate2(overTime, "yyyy-MM-dd");
				
				Date overTimeDateAdd = StringUtil.addDay(overTimeDate, 1);
				
				productOrder.setOverTime(StringUtil.date2String(overTimeDateAdd));
			}
			
			//productOrder.setOverTime(overTime);
			//获取列表数据
			
			List<Map<String ,Object>> lst = plannerService.getListByOvertimeType(productOrder);
			
			//返回列表数据
			if(lst == null || lst.size() < 1){
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
				baseTransferEntity.setData(lst);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.success"));
		}catch (Exception e) {
			log.error("getProductionOrderList 呼叫主题--------->" + e.getMessage(),
					e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 公司领导-生产通知单表查询-计划进度查看
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getScheduleToSee")
	@ResponseBody
	public BaseTransferEntity getScheduleToSee(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			
			String scheduleNo = request.getParameter("scheduleNo");
			
			String roundType = request.getParameter("roundType");
			
			ProductOrder productOrder = new ProductOrder();
			
			productOrder.setScheduleNo(scheduleNo);
			
			productOrder.setRoundType(Integer.parseInt(roundType));
			//获取列表数据
			List<Map<String, Object>> lst = productionOrderService.getProductionOrderList(productOrder);
			
			//返回列表数据
			if(lst == null || lst.size() < 1){
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("getProductionOrderList 呼叫主题--------->" + e.getMessage(),
					e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 公司领导-生产通知单表查询-计划进度审批
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getScheduleToApproval")
	@ResponseBody
	public BaseTransferEntity getScheduleToApproval(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {

			String scheduleNo = request.getParameter("scheduleNo");
			
			String roundType = request.getParameter("roundType");
			
			String apprUserId = request.getParameter("userId");
			
			ProductOrder productOrder = new ProductOrder();
			
			productOrder.setScheduleNo(scheduleNo);
			
			productOrder.setApprUserId(Integer.parseInt(apprUserId));
			
			productOrder.setRoundType(Integer.parseInt(roundType));
			//获取列表数据
			List lst = productionOrderService.getProductionOrderListArp(productOrder);
			//返回列表数据
			if(lst == null || lst.size() < 1){
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.error.list"));
				return baseTransferEntity;
			
			}
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig.getString("msg.global.success"));
		} catch (Exception e) {
			log.error("getProductionOrderList 呼叫主题--------->" + e.getMessage(),
					e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}
	/**
	 * 公司领导-生产通知单表查询-审批通过/驳回
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/updateRoundTypeByProductCode")
	@ResponseBody
	public BaseTransferEntity updateRoundTypeByProductCode(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			//将此字段改为roundType，而checkRound则与productCode/scheduleNo同为条件。
			//int checkRound = Integer.parseInt(request.getParameter("checkRound"));
			
			String productCode = request.getParameter("productCode");
			String scheduleNo = request.getParameter("scheduleNo");
			String roundType = request.getParameter("roundType");
			
			ProductOrder productOrder = new ProductOrder();
			//productOrder.setCheckRound(checkRound);
			productOrder.setRoundType(Integer.parseInt(roundType));
			productOrder.setProductCode(productCode);
			productOrder.setScheduleNo(scheduleNo);
			productionOrderService.updateRoundTypeByProductCode(productOrder);
			//返回列表数据
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
			baseTransferEntity.setData("");
			baseTransferEntity.setDesc(MobileConfig.getString("msg.global.success"));
		} catch (Exception e) {
			log.error("getProductionOrderList 呼叫主题--------->" + e.getMessage(),
					e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}
		
		return baseTransferEntity;
	}

	/**
	 * 公司领导-生产通知单表查询-根据id计划进度查看下的详情
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/queryProductionOrderDetailsList")
	@ResponseBody
	public BaseTransferEntity queryProductionOrderDetailsList(
			HttpServletRequest request, HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			String productCode = request.getParameter("productCode");
			
			String scheduleNo = request.getParameter("scheduleNo");

			ProductOrder productOrder = new ProductOrder();

			productOrder.setProductCode(productCode);
			
			productOrder.setScheduleNo(scheduleNo);

			// 获取列表数据
			List<Map<String,Object>> lst = productionOrderService
					.queryProductionOrderDetailsList(productOrder);
			
			int notStartedCount = 0;
			
			int alreadyCompletedCount = 0;
			
			int outTimeCount = 0;
			
			for(Map<String, Object> map:lst){
				
				String state = map.get("state").toString();
				
				if(!state.equals("5")){
					
					if(state.equals("1")){
						
						notStartedCount = notStartedCount+1;
						
						Date d_overTime = (Date)map.get("overTime");
						
						if((new Date()).getTime() - d_overTime.getTime() > 0){
							
							outTimeCount++;
							
						}
						
					}else {
						
						Date d_overTime = (Date)map.get("overTime");
						
						if((new Date()).getTime() - d_overTime.getTime() > 0){
							
							outTimeCount++;
							
						}
					}
				}else if(state.equals("5")){
					
					alreadyCompletedCount = alreadyCompletedCount +1;
					
				}
			}
			
			for(Map<String, Object> map:lst){
				
				if(lst.size() == notStartedCount){
					
					map.put("status", 1);
					
				}else if(lst.size() == alreadyCompletedCount){
					
					map.put("status", 3);
					
				}else {
					map.put("status", 2);
					
				}
				
				if(outTimeCount > 0){
					
					map.put("outTimeType", 1);
					
				}else {
					
					map.put("outTimeType", 0);
					
				}
			}
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				//baseTransferEntity.setTotalCount("");
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			//baseTransferEntity.setTotalCount("");
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("getProductionOrderList 呼叫主题--------->" + e.getMessage(),
					e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 公司领导-生产通知单表查询-计划进度审批-规格、数量、轮次查询
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/queryProductionOrderParameter")
	@ResponseBody
	public BaseTransferEntity queryProductionOrderParameter(
			HttpServletRequest request, HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {

			String productCode = request.getParameter("productCode");
			String scheduleNo = request.getParameter("scheduleNo");
			//roundType为0时，为制定轮次，roundType为2时，为查看轮次
			String roundType = request.getParameter("roundType");

			ProductOrder productOrder = new ProductOrder();

			productOrder.setProductCode(productCode);
			productOrder.setScheduleNo(scheduleNo);
			
			productOrder.setRoundType(Integer.parseInt(roundType));
			// 获取列表数据
			List lst = productionOrderService
					.queryProductionOrderParameter(productOrder);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));
		} catch (Exception e) {
			log.error(
					"queryProductionOrderParameter --------->" + e.getMessage(),
					e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}
	
	/**
	 * 审批的规格与数量行
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/selectSizeAndCount")
	@ResponseBody
	public BaseTransferEntity selectSizeAndCount(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			String code=request.getParameter("productCode");
			//获取列表数据
			List list = productionOrderService.selectSizeAndCount(code);
			//返回列表数据
			if(list == null || list.size() < 1){
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
				baseTransferEntity.setData(list);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.success"));
			
		} catch (Exception e) {
			log.error("selectSizeAndCount 呼叫主题--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}
		return baseTransferEntity;
	}
	/**
	 * 生产小组按轮次统计数量
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/selectCount")
	@ResponseBody
	public BaseTransferEntity selectCount(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			String code=request.getParameter("productCode");
			//获取列表数据
			List list = productionOrderService.selectCount(code);
			//返回列表数据
			if(list == null || list.size() < 1){
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
				baseTransferEntity.setData(list);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.success"));
			
		} catch (Exception e) {
			log.error("selectCount 呼叫主题--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}
		return baseTransferEntity;
	}
	

	/**
	 * 公司领导-生产通知单表查询-计划进度审批-拆分轮次查询
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/splitRoundByFinished")
	@ResponseBody
	public BaseTransferEntity splitRoundByFinished(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			int id = Integer.parseInt(request.getParameter("id"));
			String number = request.getParameter("number");
			String round = request.getParameter("round");
			String size = request.getParameter("size");
			String productCode = request.getParameter("productCode");
			String productCount = request.getParameter("productCount");
			String scheduleNo = request.getParameter("scheduleNo");

			ProductOrder productOrder = new ProductOrder();
			productOrder.setId(id);
			productOrder.setRound(Integer.parseInt(round));
			productOrder.setSize(Integer.parseInt(size));
			productOrder.setProductCode(productCode);
			productOrder.setProductCount(Integer.parseInt(productCount));
			productOrder.setNumber(Integer.parseInt(number));
			productOrder.setScheduleNo(scheduleNo);

			productionOrderService.splitRoundByFinished(productOrder);
			// 返回列表数据

			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData("");
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));
		} catch (Exception e) {
			log.error(" --------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}
	/**
	 * 公司领导-生产通知单表查询-计划进度审批-拆分轮次查询
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/splitRound")
	@ResponseBody
	public BaseTransferEntity splitRound(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			int id = Integer.parseInt(request.getParameter("id"));
			String number = request.getParameter("number");
			String round = request.getParameter("round");
			String size = request.getParameter("size");
			String productCode = request.getParameter("productCode");
			String productCount = request.getParameter("productCount");
			String scheduleNo = request.getParameter("scheduleNo");
			
			ProductOrder productOrder = new ProductOrder();
			productOrder.setId(id);
			productOrder.setRound(Integer.parseInt(round));
			productOrder.setSize(Integer.parseInt(size));
			productOrder.setProductCode(productCode);
			productOrder.setProductCount(Integer.parseInt(productCount));
			productOrder.setNumber(Integer.parseInt(number));
			productOrder.setScheduleNo(scheduleNo);
			
			productionOrderService.splitRound(productOrder);
			// 返回列表数据
			
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData("");
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));
		} catch (Exception e) {
			log.error(" --------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}
		
		return baseTransferEntity;
	}
	
	/**
	 * 公司领导-生产通知单表查询-计划进度审批-合并轮次
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/mergeRound")
	@ResponseBody
	public BaseTransferEntity mergeRound(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			String ids = request.getParameter("ids");
			
			//String number = request.getParameter("number");
			//String round = request.getParameter("round");
			//String size = request.getParameter("size");
			//String productCode = request.getParameter("productCode");
			//String productCount = request.getParameter("productCount");
			
			ProductOrder productOrder = new ProductOrder();
			productOrder.setIds(ids);
			//productOrder.setRound(Integer.parseInt(round));
			//productOrder.setSize(Integer.parseInt(size));
			//productOrder.setProductCode(productCode);
			//productOrder.setProductCount(Integer.parseInt(productCount));
			//productOrder.setNumber(Integer.parseInt(number));
			
			productionOrderService.mergeRound(productOrder);
			// 返回列表数据
			
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData("");
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));
		} catch (Exception e) {
			log.error(" --------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}
		
		return baseTransferEntity;
	}

	/**
	 * 公司领导-生产通知单表查询-根据id计划进度查看下的审批
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/queryProductionOrderApprovalList")
	@ResponseBody
	public BaseTransferEntity queryProductionOrderApprovalList(
			HttpServletRequest request, HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			String productCode = request.getParameter("productCode");
			String scheduleNo = request.getParameter("scheduleNo");

			ProductOrder productOrder = new ProductOrder();

			productOrder.setProductCode(productCode);
			productOrder.setScheduleNo(scheduleNo);

			// 获取列表数据
			List lst = productionOrderService
					.queryProductionOrderDetailsList(productOrder);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				//baseTransferEntity.setTotalCount("");
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			//baseTransferEntity.setTotalCount("");
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error(
					"queryProductionOrderApprovalList --------->"
							+ e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 公司领导-生产通知单表查询-计划进度查看通过排程号查询
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getScheduleToSeeByScheduleNo")
	@ResponseBody
	public BaseTransferEntity getScheduleToSeeByScheduleNo(
			HttpServletRequest request, HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			String scheduleNo = request.getParameter("scheduleNo");
			ProductOrder order = new ProductOrder();
			order.setScheduleNo(scheduleNo);
			// 获取列表数据
			List lst = productionOrderService
					.getProductionOrderByScheduleNo(order);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				//baseTransferEntity.setTotalCount("");
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			//baseTransferEntity.setTotalCount("");
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error("getProductionOrderList 呼叫主题--------->" + e.getMessage(),
					e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 统计分析-质检通过时间
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getqualityChecksByTime")
	@ResponseBody
	public BaseTransferEntity getqualityChecksByTime(
			HttpServletRequest request, HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			
			String processId = request.getParameter("processId");
			String productCode = request.getParameter("productCode");
			
			String startTime = request.getParameter("startTime");
			String overTime = request.getParameter("overTime");
			String userId = request.getParameter("userId");
			ProductOrder productOrder = new ProductOrder();
			
			productOrder.setId(Integer.parseInt(processId));
			
			List<Map<String,Object>> processNameLst = userService.getProcessNameByUser(Integer.parseInt(userId));
			
			Map<String, Object> processNameMap = processNameLst.get(0);
			
			String processName = processNameMap.get("processName").toString();
			
			productOrder.setProcessName(processName);
			
			productOrder.setProductCode(productCode);

			if(StringUtil.isEmpty(startTime) && StringUtil.isEmpty(overTime)){
				
				startTime = sdf.format(StringUtil.MinusDay(new Date(), 7));
				
				overTime = sdf.format(new Date());
			}
			
			productOrder.setStartTime(startTime);
			
			if(!StringUtil.isEmpty(overTime)){
				
				Date overTimeDate = StringUtil.parseDate2(overTime, "yyyy-MM-dd");
				
				Date overTimeDateAdd = StringUtil.addDay(overTimeDate, 1);
				
				productOrder.setOverTime(StringUtil.date2String(overTimeDateAdd));
			}
			
			//productOrder.setOverTime(overTime);
			
			// 获取列表数据
			List lst = productionOrderService.getqualityChecksByTime(productOrder);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				//baseTransferEntity.setTotalCount("");
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			//baseTransferEntity.setTotalCount("");
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));
		} catch (Exception e) {
			log.error("getProductionOrderList 呼叫主题--------->" + e.getMessage(),
					e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 统计分析-质检通过产品号
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getqualityChecksByproductNo")
	@ResponseBody
	public BaseTransferEntity getqualityChecksByproductNo(
			HttpServletRequest request, HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			String productNo = request.getParameter("productNo");
			// 获取列表数据
			List lst = productionOrderService
					.getqualityChecksByproductNo(productNo);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				//baseTransferEntity.setTotalCount("");
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			//baseTransferEntity.setTotalCount("");
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));
		} catch (Exception e) {
			log.error("getProductionOrderList 呼叫主题--------->" + e.getMessage(),
					e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 统计分析-质检通过款号
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getqualityChecksByNumbers")
	@ResponseBody
	public BaseTransferEntity getqualityChecksByNumbers(
			HttpServletRequest request, HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			String numbers = request.getParameter("numbers");
			// 获取列表数据
			List lst = productionOrderService
					.getqualityChecksByNumbers(numbers);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				//baseTransferEntity.setTotalCount("");
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			//baseTransferEntity.setTotalCount("");
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));
		} catch (Exception e) {
			log.error("getProductionOrderList 呼叫主题--------->" + e.getMessage(),
					e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}
	/**
	 * 统计分析-质检多条件查询
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getqualityChecksByMany")
	@ResponseBody
	public BaseTransferEntity getqualityChecksByMany(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		try {
			
			String pocessName = request.getParameter("pocessName");
			String productCode = request.getParameter("productCode");
			String startTime = request.getParameter("startTime");
			String endTime = request.getParameter("endTime");
			
			if(!StringUtil.isEmpty(endTime)){
				
				Date overTimeDate = StringUtil.parseDate2(endTime, "yyyy-MM-dd");
				
				endTime = StringUtil.date2String(StringUtil.addDay(overTimeDate, 1));
			}
			
			//productOrder.setOverTime(StringUtil.date2String(overTimeDateAdd));
			
			//获取列表数据
			List lst = productionOrderService.getqualityChecksByMany(productCode,pocessName,startTime,endTime);
			//返回列表数据
			if(lst == null || lst.size() < 1){
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig.getString("msg.global.success"));
		} catch (Exception e) {
			log.error("getProductionOrderList 呼叫主题--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}
	
	/**
	 * 统计分析-工序
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getPrList")
	@ResponseBody
	public BaseTransferEntity getPrList(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			//获取列表数据
			List lst = productionOrderService.getPrList();
			//返回列表数据
			if(lst == null || lst.size() < 1){
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig.getString("msg.global.success"));
		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}
			
		
		return baseTransferEntity;
	}
	
	/**
	 * 统计分析-质检通过工序查询
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getqualityChecksByProcess")
	@ResponseBody
	public BaseTransferEntity getqualityChecksByProcess(
			HttpServletRequest request, HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			String process = request.getParameter("process");
			// String productNo = request.getParameter("productNo");
			// String numbers = request.getParameter("numbers");
			// String process = request.getParameter("process");
			// 获取列表数据
			List lst = productionOrderService
					.getqualityChecksByProcess(process);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				//baseTransferEntity.setTotalCount("");
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			//baseTransferEntity.setTotalCount("");
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));
		} catch (Exception e) {
			log.error("getProductionOrderList 呼叫主题--------->" + e.getMessage(),
					e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 公司领导-统计分析-->补料
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/selectProduction")
	@ResponseBody
	public BaseTransferEntity selectProduction(HttpServletRequest request,

	HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		try {
			
			String startTime = request.getParameter("startTime");
			String endTime = request.getParameter("endTime");
			
			if(!StringUtil.isEmpty(endTime)){
				
				Date overTimeDate = StringUtil.parseDate2(endTime, "yyyy-MM-dd");
				
				endTime = StringUtil.date2String(StringUtil.addDay(overTimeDate, 1));
			}

			
			//productOrder.setOverTime(StringUtil.date2String(overTimeDateAdd));
			//获取列表数据
			List<Map<String,Object>> lst = productionOrderService.selectProduction(startTime,endTime);
			//返回列表数据
			if(lst == null || lst.size() < 1){
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig.getString("msg.global.success"));
			
		} catch (Exception e) {
			log.error("selectProduction 呼叫主题--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}

	/**
	 * 公司领导-统计分析-->人员
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/selectUserByRoleType")
	@ResponseBody
	public BaseTransferEntity selectUserByRoleType(HttpServletRequest request,
			HttpServletResponse response) {

		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			//获取列表数据
			List list = productionOrderService.selectUserByRoleType();
			//返回列表数据
			if(list == null || list.size() < 1){
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
				baseTransferEntity.setData(list);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.success"));
		
		} catch (Exception e) {
			log.error("getUserList 呼叫主题--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}
	
	/**
	 * 使用Id删除生产通知单
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/deleteProductOrderById")
	@ResponseBody
	public BaseTransferEntity deleteProductOrderById(HttpServletRequest request,
			HttpServletResponse response) {
		
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			
			
			String id = request.getParameter("id");
			
			ProductOrder productOrder = new ProductOrder();
			
			productOrder.setId(Integer.parseInt(id));
			
			//获取列表数据
			productionOrderService.deleteProductOrderById(productOrder);
			//返回列表数据
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
			baseTransferEntity.setData("");
			baseTransferEntity.setDesc(MobileConfig.getString("msg.global.success"));
			
		} catch (Exception e) {
			log.error("deleteProductOrderById 使用Id删除生产通知单--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}
		
		return baseTransferEntity;
	}

}
